package com.google.android.material.datepicker;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import b.f.l.s;
import c.b.a.b.f;
import com.google.android.material.datepicker.h;

class n extends RecyclerView.g<b> {

    /* renamed from: c  reason: collision with root package name */
    private final a f2269c;

    /* renamed from: d  reason: collision with root package name */
    private final d<?> f2270d;
    /* access modifiers changed from: private */
    public final h.l e;
    private final int f;

    class a implements AdapterView.OnItemClickListener {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ MaterialCalendarGridView f2271b;

        a(MaterialCalendarGridView materialCalendarGridView) {
            this.f2271b = materialCalendarGridView;
        }

        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            if (this.f2271b.getAdapter().j(i)) {
                n.this.e.a(this.f2271b.getAdapter().getItem(i).longValue());
            }
        }
    }

    public static class b extends RecyclerView.d0 {
        final TextView t;
        final MaterialCalendarGridView u;

        b(LinearLayout linearLayout, boolean z) {
            super(linearLayout);
            TextView textView = (TextView) linearLayout.findViewById(f.month_title);
            this.t = textView;
            s.f0(textView, true);
            this.u = (MaterialCalendarGridView) linearLayout.findViewById(f.month_grid);
            if (!z) {
                this.t.setVisibility(8);
            }
        }
    }

    n(Context context, d<?> dVar, a aVar, h.l lVar) {
        l r = aVar.r();
        l o = aVar.o();
        l q = aVar.q();
        if (r.compareTo(q) > 0) {
            throw new IllegalArgumentException("firstPage cannot be after currentPage");
        } else if (q.compareTo(o) <= 0) {
            this.f = (m.f * h.q(context)) + (i.A(context) ? h.q(context) : 0);
            this.f2269c = aVar;
            this.f2270d = dVar;
            this.e = lVar;
            B(true);
        } else {
            throw new IllegalArgumentException("currentPage cannot be after lastPage");
        }
    }

    /* access modifiers changed from: package-private */
    public l E(int i) {
        return this.f2269c.r().q(i);
    }

    /* access modifiers changed from: package-private */
    public CharSequence F(int i) {
        return E(i).o();
    }

    /* access modifiers changed from: package-private */
    public int G(l lVar) {
        return this.f2269c.r().r(lVar);
    }

    /* renamed from: H */
    public void s(b bVar, int i) {
        l q = this.f2269c.r().q(i);
        bVar.t.setText(q.o());
        MaterialCalendarGridView materialCalendarGridView = (MaterialCalendarGridView) bVar.u.findViewById(f.month_grid);
        if (materialCalendarGridView.getAdapter() == null || !q.equals(materialCalendarGridView.getAdapter().f2266b)) {
            m mVar = new m(q, this.f2270d, this.f2269c);
            materialCalendarGridView.setNumColumns(q.f);
            materialCalendarGridView.setAdapter((ListAdapter) mVar);
        } else {
            materialCalendarGridView.getAdapter().notifyDataSetChanged();
        }
        materialCalendarGridView.setOnItemClickListener(new a(materialCalendarGridView));
    }

    /* renamed from: I */
    public b u(ViewGroup viewGroup, int i) {
        LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(viewGroup.getContext()).inflate(c.b.a.b.h.mtrl_calendar_month_labeled, viewGroup, false);
        if (!i.A(viewGroup.getContext())) {
            return new b(linearLayout, false);
        }
        linearLayout.setLayoutParams(new RecyclerView.p(-1, this.f));
        return new b(linearLayout, true);
    }

    public int g() {
        return this.f2269c.p();
    }

    public long h(int i) {
        return this.f2269c.r().q(i).p();
    }
}
